GdkGLContext: Add display property
authorAlexander Larsson <alexl@redhat.com>
Mon, 3 Nov 2014 12:20:55 +0000 (13:20 +0100)
committerAlexander Larsson <alexl@redhat.com>
Mon, 3 Nov 2014 12:20:55 +0000 (13:20 +0100)
We need to use this in the code path where we make the context
non-current during destroy, because at that point the window
could be destroyed and gdk_window_get_display() would return
NULL.

gdk/gdkglcontext.c
gdk/gdkglcontext.h
gdk/wayland/gdkglcontext-wayland.c
gdk/x11/gdkglcontext-x11.c

index 48f444a5947e3e5dd26b62fe77093c6a95eae236..697eb2ffa33e3ac5ea2bba0cad2266f12724bb18 100644 (file)
@@ -79,6 +79,7 @@
 #include <epoxy/gl.h>
 
 typedef struct {
+  GdkDisplay *display;
   GdkWindow *window;
   GdkGLContext *shared_context;
   GdkGLProfile profile;
@@ -91,6 +92,7 @@ typedef struct {
 enum {
   PROP_0,
 
+  PROP_DISPLAY,
   PROP_WINDOW,
   PROP_PROFILE,
   PROP_SHARED_CONTEXT,
@@ -117,6 +119,7 @@ gdk_gl_context_dispose (GObject *gobject)
   if (current == context)
     g_private_replace (&thread_current_context, NULL);
 
+  g_clear_object (&priv->display);
   g_clear_object (&priv->window);
   g_clear_object (&priv->shared_context);
 
@@ -133,6 +136,20 @@ gdk_gl_context_set_property (GObject      *gobject,
 
   switch (prop_id)
     {
+    case PROP_DISPLAY:
+      {
+        GdkDisplay *display = g_value_get_object (value);
+
+        if (display)
+          g_object_ref (display);
+
+        if (priv->display)
+          g_object_unref (priv->display);
+
+        priv->display = display;
+      }
+      break;
+
     case PROP_WINDOW:
       {
         GdkWindow *window = g_value_get_object (value);
@@ -175,6 +192,10 @@ gdk_gl_context_get_property (GObject    *gobject,
 
   switch (prop_id)
     {
+    case PROP_DISPLAY:
+      g_value_set_object (value, priv->display);
+      break;
+
     case PROP_WINDOW:
       g_value_set_object (value, priv->window);
       break;
@@ -197,6 +218,22 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
+  /**
+   * GdkGLContext:display:
+   *
+   * The #GdkWindow the gl context is bound to.
+   *
+   * Since: 3.16
+   */
+  obj_pspecs[PROP_DISPLAY] =
+    g_param_spec_object ("display",
+                         P_("Display"),
+                         P_("The GDK display the context is from"),
+                         GDK_TYPE_DISPLAY,
+                         G_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT_ONLY |
+                         G_PARAM_STATIC_STRINGS);
+
   /**
    * GdkGLContext:window:
    *
@@ -329,7 +366,7 @@ gdk_gl_context_make_current (GdkGLContext *context)
   if (current == context)
     return;
 
-  if (gdk_display_make_gl_context_current (gdk_window_get_display (priv->window), context))
+  if (gdk_display_make_gl_context_current (priv->display, context))
     {
       g_private_replace (&thread_current_context, g_object_ref (context));
       if (!priv->realized)
@@ -337,6 +374,26 @@ gdk_gl_context_make_current (GdkGLContext *context)
     }
 }
 
+/**
+ * gdk_gl_context_get_display:
+ * @context: a #GdkGLContext
+ *
+ * Retrieves the #GdkDisplay the @context is created for
+ *
+ * Returns: (transfer none): a #GdkDisplay or %NULL
+ *
+ * Since: 3.16
+ */
+GdkDisplay *
+gdk_gl_context_get_display (GdkGLContext *context)
+{
+  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
+
+  g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), NULL);
+
+  return priv->display;
+}
+
 /**
  * gdk_gl_context_get_window:
  * @context: a #GdkGLContext
@@ -417,7 +474,7 @@ gdk_gl_context_clear_current (void)
     {
       GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (current);
 
-      if (gdk_display_make_gl_context_current (gdk_window_get_display (priv->window), NULL))
+      if (gdk_display_make_gl_context_current (priv->display, NULL))
         g_private_replace (&thread_current_context, NULL);
     }
 }
index e78e9b44b7168b225fc885e681339eb3f4c524f9..be71ae43820fdca92ccfff5a2b65d276039d75b7 100644 (file)
@@ -42,6 +42,8 @@ GQuark gdk_gl_error_quark (void);
 GDK_AVAILABLE_IN_3_16
 GType gdk_gl_context_get_type (void) G_GNUC_CONST;
 
+GDK_AVAILABLE_IN_3_16
+GdkDisplay *            gdk_gl_context_get_display      (GdkGLContext *context);
 GDK_AVAILABLE_IN_3_16
 GdkWindow *             gdk_gl_context_get_window       (GdkGLContext *context);
 GDK_AVAILABLE_IN_3_16
index 4c80a802de0685d1b37ba7174bf9ac312e8dae32..04d90947934b23bcd563f7b698c357e496b2c289 100644 (file)
@@ -365,6 +365,7 @@ gdk_wayland_window_create_gl_context (GdkWindow     *window,
             g_print ("Created EGL context[%p]\n", ctx));
 
   context = g_object_new (GDK_TYPE_WAYLAND_GL_CONTEXT,
+                          "display", display,
                           "window", window,
                           "profile", profile,
                           "shared-context", share,
index 4315bfd7aa954ead8ba4277c24f19962ec493f3e..2542b01cc2d75e82e90a8f0fe17b7491df4e0c6f 100644 (file)
@@ -206,7 +206,7 @@ gdk_x11_gl_context_end_frame (GdkGLContext *context,
 {
   GdkX11GLContext *context_x11 = GDK_X11_GL_CONTEXT (context);
   GdkWindow *window = gdk_gl_context_get_window (context);
-  GdkDisplay *display = gdk_window_get_display (window);
+  GdkDisplay *display = gdk_gl_context_get_display (context);
   Display *dpy = gdk_x11_display_get_xdisplay (display);
   GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
   DrawableInfo *info;
@@ -503,8 +503,7 @@ gdk_x11_gl_context_dispose (GObject *gobject)
   if (context_x11->glx_context != NULL)
     {
       GdkGLContext *context = GDK_GL_CONTEXT (gobject);
-      GdkWindow *window = gdk_gl_context_get_window (context);
-      GdkDisplay *display = gdk_window_get_display (window);
+      GdkDisplay *display = gdk_gl_context_get_display (context);
       Display *dpy = gdk_x11_display_get_xdisplay (display);
 
       if (glXGetCurrentContext () == context_x11->glx_context)
@@ -1119,6 +1118,7 @@ gdk_x11_window_create_gl_context (GdkWindow    *window,
                      is_direct ? "direct" : "indirect"));
 
   context = g_object_new (GDK_TYPE_X11_GL_CONTEXT,
+                          "display", display,
                           "window", window,
                           "profile", profile,
                           "shared-context", share,